
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

class Base():
    #判断 使用不同浏览器如何做
    def __init__(self,driver):
        self.driver = driver

    def open_url(self,url):
        self.driver.get(url)

    #要求异常时，截图命名以时间方式命名【年月日时分秒】
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver: driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)

    #点击
    def click(self,loc):
        self.find_element(loc).click()

    #输入
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)

    #回车
    def send_enter(self,loc):
        self.find_element(loc).send_keys(Keys.ENTER)

    #鼠标悬停
    def move_to_element(self,loc):
        ActionChains(self.driver).click(self.find_element(loc)).perform()

    #全选
    def allin(self,loc):
        self.find_element(loc).send_keys(Keys.CONTROL,'a')

    #复制
    def ctrlc(self,loc):
        self.find_element(loc).send_keys(Keys.CONTROL,'c')

    #粘贴
    def ctrlv(self,loc):
        self.find_element(loc).send_keys(Keys.CONTROL,'v')